package com.tywj.buscustomerapp.view.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.kyleduo.switchbutton.SwitchButton;
import com.tywj.buscustomerapp.R;
import com.tywj.buscustomerapp.utils.SPUtils;
import com.tywj.buscustomerapp.utils.ToastUtils;
import com.tywj.buscustomerapp.view.myview.ToastJoe;
import com.umeng.analytics.MobclickAgent;

import butterknife.BindView;

public class MoreActivity extends BaseActivity {
    @BindView(R.id.head_left) ImageView back;
    @BindView(R.id.head_title) TextView title;
    @BindView(R.id.more_pwd) TextView pwdSetting;
    @BindView(R.id.more_station) SwitchButton switchButton;
    @BindView(R.id.more_use) TextView useInfo;
    @BindView(R.id.more_about) TextView about;
    @BindView(R.id.more_login_out) TextView loginOut;


    @Override
    protected int getContentId() {
        return R.layout.activity_more;
    }

    @Override
    protected void initWidget(Bundle savedInstanceState) {
        super.initWidget(savedInstanceState);
        title.setText("更多");
        boolean is = SPUtils.getIsStation(getApplicationContext());
        if (is)
            switchButton.setChecked(true);
        else
            switchButton.setChecked(false);

    }

    @Override
    protected void initData() {
        super.initData();
        switchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SPUtils.rememberIsStation(getApplicationContext(),isChecked);
            }
        });
    }

    @Override
    protected void initClick() {
        super.initClick();
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        loginOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SPUtils.clearUserPhone(getApplicationContext());
                ToastJoe.getmToastJoe().ToastShowRight(MoreActivity.this,null,"退出登录成功");
                finish();
            }
        });

        useInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MoreActivity.this,InfoActivity.class);
                intent.putExtra("type",0);
                startActivity(intent);
            }
        });

        about.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MoreActivity.this,AboutActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("更多");
        MobclickAgent.onResume(this); //统计时长

    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("更多");
        MobclickAgent.onPause(this);
    }
}
